package com.zzty.zzlp.serviceimpl;

import com.zzty.zzlp.commom.PropertyUtil;
import com.zzty.zzlp.dao.TwitterMapper;
import com.zzty.zzlp.entity.Twitter;
import com.zzty.zzlp.entity.User;
import com.zzty.zzlp.service.TwitterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Array;
import java.sql.Time;
import java.util.*;

@Service
public class TwitterServiceImpl implements TwitterService {
    @Autowired
    TwitterMapper twitterMapper;



    public void publishTwitter(Twitter twitter){
        twitterMapper.insertTwitter(twitter);
    }


    public List<Twitter> searchTwitter() {
        return twitterMapper.selectAll();
    }

    public List<Twitter> searchSelf(Integer author) {
        return twitterMapper.selectSelf(author);
    }

    public List getImg(){
        List<Twitter> listt = searchTwitter() ;
        List imgList = new ArrayList() ;
        for(int i = 0 ; i < listt.size();i++){

            String imgs = listt.get(i).getImg();
            if(imgs!=null){
                String path = PropertyUtil.prop.getProperty("path.img");
                String [] tmp=imgs.split("\\|");
                for(int index = 0 ; index < tmp.length ;index ++ ){
                    System.out.println(tmp[index]);
                    if(tmp[index]!= "" && tmp[index] != null&&tmp.length >= 1)
                    tmp[index] = path + tmp[index];
                    System.out.println("tmp==========="+tmp[index]);
                }
                imgList = Arrays.asList(tmp);
                listt.get(i).setImgs(imgList);
                tmp = null;

            }
        }
        System.out.println("list ============="+listt);
        return  listt;
    }


    public List getSelfImg(Integer author){
        List<Twitter> listts = searchSelf(author) ;
        List imgList = new ArrayList() ;
        for(int i = 0 ; i < listts.size();i++){

            String imgs = listts.get(i).getImg();
            if(imgs!=null){
                String path = PropertyUtil.prop.getProperty("path.img");
                String [] tmp=imgs.split("\\|");
                for(int index = 0 ; index < tmp.length ;index ++ ){
                    System.out.println(tmp[index]);
                    if(tmp[index]!= "" && tmp[index] != null&&tmp.length >= 1)
                        tmp[index] = path + tmp[index];
                    System.out.println("tmp==========="+tmp[index]);
                }
                imgList = Arrays.asList(tmp);
                listts.get(i).setImgs(imgList);
                tmp = null;
            }

        }
        System.out.println("list ============="+listts);
        return  listts;
    }
}
